package com.shixulin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shixulin.domain.ResponseResult;
import com.shixulin.entity.UserAnswer;
import com.shixulin.mapper.UserAnswerMapper;
import com.shixulin.service.UserAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (UserAnswer)表服务实现类
 *
 * @author makejava
 * @since 2023-12-17 18:05:54
 */
@Service("userAnswerService")
public class UserAnswerServiceImpl extends ServiceImpl<UserAnswerMapper, UserAnswer> implements UserAnswerService {

    @Autowired
    private UserAnswerMapper userAnswerMapper;

    @Override
    public ResponseResult saveUserAnswer(List<UserAnswer> userAnswer) {
        int insert = userAnswerMapper.saveUserAnswer(userAnswer);

        if (insert>0){
            return new ResponseResult(300,"成功");
        }else {
            return new ResponseResult(500, "失败");
        }

    }

    @Override
    public ResponseResult getUserAnswer(int userId, int paperId, int examStatus) {

        List<UserAnswer> userAnswerList = userAnswerMapper.getUserAnswer(userId,paperId,examStatus);

        if(userAnswerList!=null&&!userAnswerList.isEmpty()){
            return new ResponseResult(300,"成功",userAnswerList);
        }else {
            return new ResponseResult(500, "失败");
        }

    }
}
